/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package stuff.ext;

import org.springframework.dao.DataAccessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import stuff.AccountManager;
import stuff.Account;

/**
 *
 * @author Николай
 */
public class AccountServices implements UserDetailsService {

    @Autowired
    private AccountManager accMgr;

    public AccountServices() {
    }

    @Override
    public UserDetails loadUserByUsername(String s) throws
            UsernameNotFoundException,
            DataAccessException {
        Account acc = accMgr.getAccount(s);
        if (acc == null) {
            throw new UsernameNotFoundException("User no found");
        }
        AccountDetsImpl adi = new AccountDetsImpl(acc);
        return adi;
    }
}
